package com.tarena.lbs.user.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.user.pojo.param.UserGroupParam;
import com.tarena.lbs.user.pojo.query.UserGroupQuery;
import com.tarena.lbs.user.pojo.vo.UserGroupVO;
import com.tarena.lbs.user.service.UserGroupService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户人群业务相关
 */
@Slf4j
@Tag(name = "用户人群管理")
@RestController
public class UserGroupController {

    @Autowired
    private UserGroupService userGroupService;

    @Operation(summary = "人群数据分页列表")
    @PostMapping("/admin/basic/userGroup/list")
    public Result<PageResult<UserGroupVO>> pageList(@RequestBody UserGroupQuery query)
        throws BusinessException{
        log.info("查询用户分组列表，入参：{}", query);
        log.info("查询条件详情 - 商家ID：{}，人群名称：{}，标签ID：{}，发布状态：{}，开始时间：{}，结束时间：{}", 
                query.getBusinessId(), query.getGroupName(), query.getTagIds(), 
                query.getPublishStatus(), query.getStartTime(), query.getEndTime());
        PageResult<UserGroupVO> pageResult = userGroupService.pageList(query);
        log.info("查询用户分组列表成功，出参：{}", pageResult);
        return new Result<>(pageResult);
    }

    @Operation(summary = "保存人群数据")
    @PostMapping("/admin/basic/userGroup/save")
    public Result<Void> save(@RequestBody UserGroupParam param)throws BusinessException
    {
        log.debug("保存用户分组，入参：{}", param);
        userGroupService.save(param);
        log.debug("保存用户分组成功，入参：{}", param);
        return Result.success();
    }

}
